<?php if (!defined("BASEPATH")) exit("No direct script access allowed"); ?>

<script type="text/javascript">
	Ext.onReady(function() {

		Ext.namespace('DataEdit');

		DataEdit.publish = function(entity, id, name, publish) {
			Ext.MessageBox.confirm('<?=$this->db->escape_str($this->lang->line("CONFIRMATION"))?>', ((publish == 1)?('<?=$this->db->escape_str($this->lang->line("ARE_YOU_SURE_YOU_WOULD_LIKE_TO_PUBLISH_THE_ITEMS"))?>'):('<?=$this->db->escape_str($this->lang->line("ARE_YOU_SURE_YOU_WOULD_LIKE_TO_CANCEL_THE_UNPUBLISHED_DATA"))?>')) + ' (' + name + ')?' , function(btn) {
				if(btn == 'yes') {
					Ext.Ajax.request({url: '<?=site_url()?>admin/article_insert_update', params: 'publish=' + publish + '&ENTITY=' + entity + '&ID=' + id, success: function() {
						Ext.getCmp(entity.toLowerCase() + 'Grid').getStore().reload(Ext.getCmp(entity.toLowerCase() + 'Grid').lastOptions);
						}
					});
				}
			});
		}

		DataEdit.unpublish = function(entity, id, name, publish) {
			Ext.MessageBox.confirm('<?=$this->db->escape_str($this->lang->line("CONFIRMATION"))?>', '<?=$this->db->escape_str($this->lang->line("ALL_UNPUBLISHED_DATA_WILL_BE_ERASED_ARE_YOU_SURE_TO_CONTINUE"))?>' , function(btn) {
				if(btn == 'yes') {
					Ext.Ajax.request({url: '<?=site_url()?>admin/article_insert_update', params: 'publish=' + publish + '&ENTITY=' + entity + '&ID=' + id, success: function() {
						Ext.getCmp(entity.toLowerCase() + 'Grid').getStore().reload(Ext.getCmp(entity.toLowerCase() + 'Grid').lastOptions);
						}
					});
				}
			});
		}
	
		var winArticle; // edit ablak
		var articleForm; // form panel

		var store = new Ext.data.JsonStore({
			totalProperty: 'total', 
			root: 'results', 
			sortInfo: {field: 'artCreatetime', direction: 'DESC'},
			remoteSort: true,
			proxy : new Ext.data.HttpProxy({
				url: '<?=site_url()?>admin/get_article',
				method: 'GET'
			}),
			fields: [
				{name: 'artId'},
				{name: 'artName'},
				{name: 'artUrlName'},
				{name: 'artLead'},
				{name: 'artText'},
				{name: 'artHighlight'},
				{name: 'artCreatetime'},
				{name: 'mptList'},
				{name: 'couList'},
				{name: 'cityList'},
				{name: 'insList'},
				{name: 'majList'},
				{name: 'subList'},
				{name: 'entList'},
				{name: 'entUrlList'},
				{name: 'usrEmail'},
				{name: 'artPosition'},
				{name: 'szoLname'},
				{name: 'artTempFlag'}
			]
		});

		var grid = new Ext.grid.GridPanel({
			store: store,
			id: 'artGrid',
			viewConfig:{
				emptyText: '<?=$this->db->escape_str($this->lang->line("THERE_IS_CURRENTLY_NO_DATA_TO_DISPLAY"))?>',
				getRowClass: function(record, index) {
					if(record.data.artTempFlag == 'I') return 'temp_data_exists';
					else if(record.data.artPresenter == 'I') return 'presenter_live';
				}
			},
			columns: [
				{header: '<?=$this->db->escape_str($this->lang->line("TITLE"))?>', width: 200, sortable: true, dataIndex: 'artName'},
				{id:'artLead', header: '<?=$this->db->escape_str($this->lang->line("LEAD"))?>', width: 350, sortable: false, dataIndex: 'artLead', renderer: function (val) { 
					return val;
					stripVal = val.replace(/<[^>]*>/g, '');
					if(stripVal.length > 400) {
						return stripVal.substr(0,400) + '...';
					} else {
						return val;
					}
				}},
				<? if(Common::isSuperAdmin()) { ?>
				{header: '<?=$this->db->escape_str($this->lang->line("EMPHASIZED"))?>', width: 70, sortable: true, align: 'center', dataIndex: 'artHighlight', renderer: function(val) { 
					return ((val == 'I')?('<a onclick="return false;">'):('')) + '<span style="color:' + ((val == 'I')?('green'):('red')) + ';">' + ((val == 'I')?('<?=$this->lang->line("YES")?>'):('<?=$this->lang->line("NO")?>')) + '</span>' + ((val == 'I')?('</a>'):('')); 
				}},
				{header: '<?=$this->db->escape_str($this->lang->line("POSITION"))?>', width: 70, sortable: true, align: 'center', dataIndex: 'szoLname', renderer: function(val, cell, record) {
					if(record.data.artPosition == 'F' || record.data.artPosition == 'H' || record.data.artPosition == 'R') {
						return '<a onclick="return false;">' + val + '</a>';
					} else {
						return val;
					}
				}},
				<? } ?>
				{id: 'entList', header: '<?=$this->db->escape_str($this->lang->line("ATTACHING"))?>', width: 200, sortable: true, dataIndex: 'entList'},
				{header: '<?=$this->db->escape_str($this->lang->line("RECORDING_TIME"))?>', width: 140, sortable: true, dataIndex: 'artCreatetime'}
			],
			stripeRows: true,
			autoExpandColumn: 'artLead',
			autoHeight: true,
			autoWidth: true,
			sm: new Ext.grid.RowSelectionModel({singleSelect:true}),

			listeners: {

				cellclick: function(grid, rowIndex, columnIndex, event) {
					if(columnIndex == 3 || columnIndex == 2) {
						var record = grid.getStore().getAt(rowIndex);
						if(record.data.artPosition == 'F' || record.data.artPosition == 'H' || record.data.artPosition == 'R' || record.data.artHighlight == 'I') {
						
							var storeFH = new Ext.data.JsonStore({
								totalProperty: 'total', 
								root: 'results', 
								sortInfo: {field: 'artOrder', direction: 'ASC'},
								remoteSort: true,
								proxy : new Ext.data.HttpProxy({
									url: '<?=site_url()?>admin/get_article/' + ((record.data.artHighlight == 'I' && columnIndex == 2)?('I'):(record.data.artPosition)),
									method: 'GET',
								}),
								autoLoad: true,
								fields: [
									{name: 'artId'},
									{name: 'artName'},
									{name: 'artUrlName'},
									{name: 'artLead'},
									{name: 'artText'},
									{name: 'artHighlight'},
									{name: 'artCreatetime'},
									{name: 'mptList'},
									{name: 'couList'},
									{name: 'cityList'},
									{name: 'insList'},
									{name: 'majList'},
									{name: 'subList'},
									{name: 'entList'},
									{name: 'entUrlList'},
									{name: 'usrEmail'},
									{name: 'artPosition'},
									{name: 'szoLname'},
									{name: 'artTempFlag'},
									{name: 'artOrder'}
								]
							});
						
							winArticleFH = new Ext.Window({
								iconCls: 'application_form_edit',
								layout:'',
								id: 'winArticleFH',
								bodyStyle: 'background-color:white',
								autoScroll: true,
								modal: true,
								width:700,
								floating: true,
								minWidth: 700,
								height:400,
								minHeight: 400,
								closeAction:'close',
								maximizable: false,
								title: ((columnIndex == 2)?('<?=$this->db->escape_str($this->lang->line("EMPHASIZED"))?>'):(record.data.szoLname)),

								listeners: {
									close: function() {
										store.reload(store.lastOptions);
									}
								},

								items:[
									new Ext.grid.GridPanel({
										store: storeFH,
										border: false,
										id: 'artGridFH',
										viewConfig:{
											emptyText: '<?=$this->db->escape_str($this->lang->line("THERE_IS_CURRENTLY_NO_DATA_TO_DISPLAY"))?>'
										},
										columns: [
											{id: 'artName', header: '<?=$this->db->escape_str($this->lang->line("TITLE"))?>', width: 200, sortable: false, dataIndex: 'artName'}
										],
										stripeRows: true,
										autoExpandColumn: 'artName',
										autoHeight: true,
										autoWidth: true,
										enableDragDrop: true,
										ddGroup: 'myddGroup',
										sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
										listeners: {

											render: function() {

												Ext.getCmp('artGridFH').dropZone = new Ext.dd.DropZone(Ext.getCmp('artGridFH').getView().scroller, {

													ddGroup: 'myddGroup',

													getTargetFromEvent: function(e) {
														return e.getTarget(Ext.getCmp('artGridFH').getView().rowSelector);
													},

													onNodeEnter : function(target, dd, e, data){ 
														Ext.fly(target).addClass('my-row-highlight-class');
													},

													onNodeOut : function(target, dd, e, data){ 
														Ext.fly(target).removeClass('my-row-highlight-class');
													},

													onNodeOver : function(target, dd, e, data){ 
														return Ext.dd.DropZone.prototype.dropAllowed;
													},

													onNodeDrop : function(target, dd, e, data){

														if(dd.getDragData(e)) {
															var newpos = dd.getDragData(e).rowIndex + 1;
															var selectedArtId = Ext.getCmp('artGridFH').getStore().getAt(data.rowIndex).data.artId;
															Ext.MessageBox.confirm('<?=$this->db->escape_str($this->lang->line("CONFIRMATION"))?>', '<?=$this->db->escape_str($this->lang->line("ARE_YOU_SURE_YOU_WOULD_LIKE_TO_CHANGE_THE_ORDER_OF_ARTICLES_BELOW"))?><br/><br/><p style="text-align:center;"><b>' + Ext.getCmp('artGridFH').getStore().getAt(data.rowIndex).data.artName + '(' + Ext.getCmp('artGridFH').getStore().getAt(data.rowIndex).data.artOrder + ')</b> <?=$this->db->escape_str($this->lang->line("MOVE"))?> <b>' + Ext.getCmp('artGridFH').getStore().getAt(newpos-1).data.artName + '(' + Ext.getCmp('artGridFH').getStore().getAt(newpos-1).data.artOrder + ')</b> <?=$this->db->escape_str($this->lang->line("TO_POSITION"))?></p>', 
															function(btn) {
																if(btn == 'yes') {
																	Ext.Ajax.request({url: '<?=site_url()?>admin/article_insert_update', params: 'sort=1&artPosition=' + record.data.artPosition + '&artId=' + selectedArtId + '&position=' + Ext.getCmp('artGridFH').getStore().getAt(newpos-1).data.artOrder, success: function() { Ext.getCmp('artGridFH').getStore().load(); }});
																} else {
																	//alert(Ext.getCmp('artGridFH').getStore().getAt(newpos-1).data.catOrder);
																}
															});
														}

													}
												});
											}
										}
									})
								]

							});
							winArticleFH.show(this);
						}
					}
				},
			
				rowdblclick: function(grid, rowIndex, event) {
					if(rowIndex != 'new') {
						var record = grid.getStore().getAt(rowIndex);
					} else {
						var record = new Object();
						record.data = new Object();
					}

					if(winArticle) {
						winArticle.close();
					}
					winArticle = new Ext.Window({
						iconCls: (rowIndex == 'new')?('application_form_add'):('application_form_edit'),
						bodyStyle: 'background-color:white',
						autoScroll: true,
						maximized: false,
						modal: true,
						width:800,
						floating: true,
						minWidth: 800,
						height:500,
						minHeight: 500,
						closeAction:'close',
						maximizable: false,
						title: (rowIndex == 'new')?('<?=$this->db->escape_str($this->lang->line("ADD_NEW"))?>'):('<?=$this->db->escape_str($this->lang->line("EDIT"))?> - ' + record.data.artName),

						listeners: {
							close: function() {
								//store.reload(store.lastOptions);
							}
						},

						items:[{

									border: false,

									items: articleForm = new Ext.FormPanel({
										padding: 10,
										labelAlign: 'right',
										labelWidth: 100,
										autoHeight: true,
										autoWidth: true,
										border: false,
										defaultType: 'textfield',
										waitMsgTarget: true,
										items: [{
												hidden: true,
												inputType: 'hidden',
												name: 'art_id',
												value: record.data.artId
											}, {
												xtype:'fieldset',
												title: '<?=$this->db->escape_str($this->lang->line("TITLE_OF_ARTICLE"))?>',
												autoHeight:true,
												layout: {
													type: 'anchor'
												},
												items: [{
													xtype: 'textfield',
													fieldLabel: '<?=$this->db->escape_str($this->lang->line("TITLE_OF_ARTICLE"))?>',
													name: 'art_name',
													value: record.data.artName,
													maxLength: 255,
													maxLengthText: '<?=$this->db->escape_str($this->lang->line("YOU_HAVE_EXCEEDED_THE_MAXIMUM_LENGTH"))?>',
													allowBlank: false,
													blankText: '<?=$this->db->escape_str($this->lang->line("THIS_FIELD_IS_REQUIRED"))?>',
													anchor:'100%'
												}]
											}, <? /*{
												xtype:'fieldset',
												title: '<?=$this->db->escape_str($this->lang->line("LEAD"))?>',
												autoHeight:true,
												layout: {
													type: 'anchor'
												},
												items: [{
													fieldLabel: '<?=$this->db->escape_str($this->lang->line("LEAD"))?>',
													xtype: 'htmleditor',
													enableColors: true,
													enableLinks: true,
													enableFont: true,
													enableSourceEdit: true,
													name: 'art_lead',
													name: 'art_lead',
													anchor:'100%',
													height: 200,
													value: record.data.artLead,
													listeners: {
														render: function(editor) {
															editor.getToolbar().insertButton(editor.getToolbar().items.length, {
																iconCls: 'upload-icon',
																handler: function(b,e) {
																	Ext.Msg.prompt('Insert Image', 'Image URL', function(btn, txt) {
																		if (btn == 'ok') {
																			editor.relayCmd('insertimage', txt);
																		}
																	});                                            
																}
															});
														}
													}
												}]
											},*/ ?> {
												xtype:'fieldset',
												title: '<?=$this->db->escape_str($this->lang->line("LEAD"))?>',
												autoHeight:true,
												layout: {
													type: 'anchor'
												},
												items: [{
													xtype: 'panel',
													border: false,
													html: '<textarea name="art_lead" id="art_lead" rows="10"></textarea>'
												}]
											}, <? /*{
												xtype:'fieldset',
												title: '<?=$this->db->escape_str($this->lang->line("TEXT"))?>',
												autoHeight:true,
												layout: {
													type: 'anchor'
												},
												items: [{
													fieldLabel: '<?=$this->db->escape_str($this->lang->line("TEXT"))?>',
													xtype: 'htmleditor',
													enableColors: true,
													enableLinks: true,
													id: 'art_text',
													enableFont: true,
													enableSourceEdit: true,
													name: 'art_text',
													anchor:'100%',
													height: 300,
													value: record.data.artText,
													listeners: {
														render: function(editor) {
															editor.getToolbar().insertButton(editor.getToolbar().items.length, {
																iconCls: 'upload-icon',
																handler: function(b,e) {
																	Ext.Msg.prompt('Insert Image', 'Image URL', function(btn, txt) {
																		if (btn == 'ok') {
																			editor.relayCmd('insertimage', txt);
																		}
																	});                                            
																}
															});
														}
													}
												}]
											}, */ ?>
											{
												xtype:'fieldset',
												title: '<?=$this->db->escape_str($this->lang->line("TEXT"))?>',
												autoHeight:true,
												layout: {
													type: 'anchor'
												},
												items: [{
													xtype: 'panel',
													border: false,
													html: '<textarea name="art_text" id="art_text" rows="10"></textarea>'
												}]
											},
											<? if(Common::isSuperAdmin()) { ?>
											{
												xtype:'fieldset',
												title: '<?=$this->db->escape_str($this->lang->line("POSITION"))?>',
												autoHeight:true,
												layout: {
													type: 'anchor'
												},
												items: [ new Ext.form.ComboBox({
													fieldLabel: '<?=$this->db->escape_str($this->lang->line("POSITION"))?>111',
													hiddenName:'art_position',
													store: new Ext.data.ArrayStore({
														fields: ['art_position_sname', 'art_position_lname'],
														data : <? $szotar = Common::szotar("ARTPOS"); echo Common::arr2jsobj($szotar["ARTPOS"]); ?>
													}),
													valueField:'art_position_sname',
													displayField:'art_position_lname',
													editable: false,
													mode: 'local',
													triggerAction: 'all',
													emptyText:'...',
													selectOnFocus:true,
													allowBlank: false,
													blankText: '<?=$this->db->escape_str($this->lang->line("THIS_FIELD_IS_REQUIRED"))?>',
													value: record.data.artPosition,
													anchor:'100%'
													})
												] 
											}, 
											{
												xtype:'fieldset',
												title: '<?=$this->db->escape_str($this->lang->line("EMPHASIZED"))?>',
												autoHeight:true,
												layout: {
													type: 'anchor'
												},
												items: [{
													fieldLabel: '<?=$this->db->escape_str($this->lang->line("EMPHASIZED"))?>',
													name: 'art_highlight',
													xtype: 'checkbox',
													inputValue: 'I',
													checked: record.data.artHighlight == 'I' ? true : false
												}]
											},
											<? } ?>
											{
												xtype:'fieldset',
												title: '<?=$this->db->escape_str($this->lang->line("ATTACH_OF_THE_ARTICLE"))?>',
												autoHeight:true,
												layout: {
													type: 'form'
												},
												items: [
													<? if(Common::isAdminJog("COU")) { $volt = TRUE; ?>
													{
														xtype:'fieldset',
														title: '<?=$this->db->escape_str($this->lang->line("ORSZAGHOZ"))?>',
														autoHeight:true,
														layout: {
															type: 'anchor'
														},
														items: [{
															xtype:'superboxselect',
															fieldLabel: '<?=$this->db->escape_str($this->lang->line("ORSZAGHOZ"))?>',
															name:'cou_id[]',
															renderFieldBtns: true,
															anchor:'100%',
															store: new Ext.data.ArrayStore({
																fields: ['cou_id', 'cou_name'],
																proxy : new Ext.data.HttpProxy({
																	url: '<?=site_url()?>admin/get_country/obj',
																	method: 'GET'
																}),
																autoLoad: ((rowIndex == 'new')?('true'):('false'))
															}),
															value: record.data.couList,
															mode: ((rowIndex == 'new')?('local'):('remote')),
															triggerAction: 'all',
															displayField: 'cou_name',
															displayFieldTpl: '{cou_name}',
															valueField: 'cou_id',
															navigateItemsWithTab: false
														}]
													}
													<? } ?>
													<? if(Common::isAdminJog("COU") or Common::isAdminJog("CITY")) { echo ((isset($volt))?(","):("")); $volt = TRUE; ?>
													{
														xtype:'fieldset',
														title: '<?=$this->db->escape_str($this->lang->line("FOR_CITY"))?>',
														autoHeight:true,
														layout: {
															type: 'anchor'
														},
														items: [{
															xtype:'superboxselect',
															fieldLabel: '<?=$this->db->escape_str($this->lang->line("FOR_CITY"))?>',
															name:'city_id[]',
															renderFieldBtns: true,
															anchor:'100%',
															store: new Ext.data.ArrayStore({
																fields: ['city_id', 'city_name'],
																proxy : new Ext.data.HttpProxy({
																	url: '<?=site_url()?>admin/get_city/0/obj',
																	method: 'GET'
																}),
																autoLoad: ((rowIndex == 'new')?('true'):('false'))
															}),
															value: record.data.cityList,
															mode: ((rowIndex == 'new')?('local'):('remote')),
															triggerAction: 'all',
															displayField: 'city_name',
															displayFieldTpl: '{city_name}',
															valueField: 'city_id',
															minChars: 3,
															navigateItemsWithTab: false
														}]
													}
													<? } ?>
													<? if(Common::isAdminJog("INS")) { echo ((isset($volt))?(","):("")); ?>
													{
														xtype:'fieldset',
														title: '<?=$this->db->escape_str($this->lang->line("TO_THE_INSTITUTE"))?>',
														autoHeight:true,
														layout: {
															type: 'anchor'
														},
														items: [{
															xtype:'superboxselect',
															fieldLabel: '<?=$this->db->escape_str($this->lang->line("TO_THE_INSTITUTE"))?>',
															name:'ins_id[]',
															renderFieldBtns: true,
															anchor:'100%',
															store: new Ext.data.ArrayStore({
																fields: ['ins_id', 'ins_name', 'ins_url_name', 'city_id', 'ins_priority', 'city_name'],
																proxy : new Ext.data.HttpProxy({
																	url: '<?=site_url()?>admin/get_institute/obj/false/ART',
																	method: 'GET'
																}),
																autoLoad: ((rowIndex == 'new')?('true'):('false'))
															}),
															value: record.data.insList,
															mode: ((rowIndex == 'new')?('local'):('remote')),
															triggerAction: 'all',
															tpl: '<tpl for="."><div class="x-combo-list-item" >{ins_name} ({city_name})</div></tpl>', 
															displayField: 'ins_name',
															displayFieldTpl: '{ins_name} ({city_name})',
															valueField: 'ins_id',
															minChars: 3,
															navigateItemsWithTab: false
														}]
													},
													{
														xtype:'fieldset',
														title: '<?=$this->db->escape_str($this->lang->line("TO_THE_SUBJECT"))?>',
														autoHeight:true,
														layout: {
															type: 'anchor'
														},
														items: [{
															xtype:'superboxselect',
															fieldLabel: '<?=$this->db->escape_str($this->lang->line("TO_THE_SUBJECT"))?>',
															name:'sub_id[]',
															renderFieldBtns: true,
															anchor:'100%',
															store: new Ext.data.ArrayStore({
																fields: ['sub_id', 'sub_sub_id', 'group', 'sub_name'],
																proxy : new Ext.data.HttpProxy({
																	url: '<?=site_url()?>admin/getSubject/full',
																	method: 'GET'
																}),
																autoLoad: ((rowIndex == 'new')?('true'):('false'))
															}),
															tpl: new Ext.XTemplate(
																'<tpl for=\".\">',
																'<tpl if=\"this.group != values.group\">',
																'<tpl exec=\"this.group = values.group\"></tpl>',
																'<h1>{group}</h1>',
																'</tpl>',
																'<div class=\"x-combo-list-item\">{sub_name}</div>',
																'</tpl>'
															),															
															value: record.data.subList,
															mode: ((rowIndex == 'new')?('local'):('remote')),
															triggerAction: 'all',
															//tpl: '<tpl for="."><div class="x-combo-list-item" >{maj_name} ({ins_name})</div></tpl>', 
															displayField: 'sub_name',
															displayFieldTpl: '{sub_name}',
															valueField: 'sub_id',
															minChars: 3,
															navigateItemsWithTab: false
														}]
													},													
													{
														xtype:'fieldset',
														title: '<?=$this->db->escape_str($this->lang->line("TO_THE_COURSE"))?>',
														autoHeight:true,
														layout: {
															type: 'anchor'
														},
														items: [{
															xtype:'superboxselect',
															fieldLabel: '<?=$this->db->escape_str($this->lang->line("TO_THE_COURSE"))?>',
															name:'maj_id[]',
															renderFieldBtns: true,
															anchor:'100%',
															store: new Ext.data.ArrayStore({
																fields: ['maj_id', 'maj_name', 'maj_url_name', 'ins_id', 'ins_name'],
																proxy : new Ext.data.HttpProxy({
																	url: '<?=site_url()?>admin/get_major/0/obj',
																	method: 'GET'
																}),
																autoLoad: ((rowIndex == 'new')?('true'):('false'))
															}),
															value: record.data.majList,
															mode: ((rowIndex == 'new')?('local'):('remote')),
															triggerAction: 'all',
															tpl: '<tpl for="."><div class="x-combo-list-item" >{maj_name} ({ins_name})</div></tpl>', 
															displayField: 'maj_name',
															displayFieldTpl: '{maj_name} ({ins_name})',
															valueField: 'maj_id',
															minChars: 3,
															navigateItemsWithTab: false
														}]
													}
													<? } ?>
												]
											}
										]

									})

								}

							],

							bbar: {
								items: [{
									text: '<?=$this->db->escape_str($this->lang->line("SAVE"))?>',
									handler: save,
									icon: '<?=MEDIA?>icon/disk.png'
								}, {
									xtype: 'tbseparator'
								},{
									text: '<?=$this->db->escape_str($this->lang->line("CANCEL"))?>',
									handler: close,
									icon: '<?=MEDIA?>icon/cancel.png'
								}, {
									xtype: 'tbseparator'
								},{
									text: '<?=$this->db->escape_str($this->lang->line("RESET"))?>',
									handler: function() {
										articleForm.getForm().reset();
									}
								}],
								buttonAlign : 'right'
							},
							
							listeners: {
								afterrender: function() {
									CKEDITOR.replace('art_lead', {
										on :{
											instanceReady : function() {
												this.setData(record.data.artLead);
											}
										}
									});
									CKEDITOR.replace('art_text', {
										on :{
											instanceReady : function() {
												this.setData(record.data.artText);
											}
										}
									});
								}
							}

					});
					winArticle.show(this);

				}
			},
			border: false,

			frame:false,

			tbar: {
				items: [{
						icon: '<?=MEDIA?>icon/application_form_add.png',
						text: '<?=$this->db->escape_str($this->lang->line("ADD_NEW"))?>',
						handler: function(){
							grid.fireEvent('rowdblclick', grid, 'new', new Object());
						}
					}, {
							xtype: 'tbseparator'
					}, {
						icon: '<?=MEDIA?>icon/application_form_edit.png',
						text: '<?=$this->db->escape_str($this->lang->line("EDIT"))?>',
						ref: '../editBtn',
						disabled: true,
						handler: function() {
							Ext.getCmp('artGrid').fireEvent('rowdblclick', Ext.getCmp('artGrid'), Ext.getCmp('artGrid').store.indexOf(Ext.getCmp('artGrid').getSelectionModel().getSelected()), new Object());
						}
					}, {
							xtype: 'tbseparator'
					}, {
						icon: '<?=MEDIA?>icon/application_form_delete.png',
						text: '<?=$this->db->escape_str($this->lang->line("DELETE"))?>',
						ref: '../removeBtn',
						disabled: true,
						handler: function(){
							Ext.MessageBox.confirm('<?=$this->db->escape_str($this->lang->line("CONFIRMATION"))?>', '<?=$this->db->escape_str($this->lang->line("ARE_YOU_SURE_YOU_WOULD_LIKE_TO_DELETE_THE_ARTICLE"))?> (' + grid.getSelectionModel().getSelections()[0].data.artName + ')?' , removeArticle);
						}
					}, {
						xtype: 'tbseparator'
					}, {
						icon: '<?=MEDIA?>icon/application_form_preview.png',
						text: '<?=$this->db->escape_str($this->lang->line("PREVIEW"))?>',
						ref: '../previewBtn',
						disabled: true,
						handler: function(){
							window.open('<?=site_url()?>preview/' + Ext.getCmp('artGrid').getSelectionModel().getSelections()[0].data.artUrlName);
						}
					}, {
						xtype: 'tbseparator'
					}, {
						icon: '<?=MEDIA?>icon/application_form_publish.png',
						text: '<?=$this->db->escape_str($this->lang->line("PUBLICATION"))?>',
						ref: '../publishBtn',
						disabled: true,
						handler: function(){
							DataEdit.publish('ART', Ext.getCmp('artGrid').getSelectionModel().getSelections()[0].data.artId, Ext.getCmp('artGrid').getSelectionModel().getSelections()[0].data.artName, 1);
						}
					}, {
						xtype: 'tbseparator'
					}, {
						icon: '<?=MEDIA?>icon/application_form_publish_delete.png',
						text: '<?=$this->db->escape_str($this->lang->line("CANCELLING_OF_UNPUBLISHED_DATA"))?>',
						ref: '../publishBtnDelete',
						disabled: true,
						handler: function(){
							DataEdit.publish('ART', Ext.getCmp('artGrid').getSelectionModel().getSelections()[0].data.artId, Ext.getCmp('artGrid').getSelectionModel().getSelections()[0].data.artName, 0);
						}
					}, {
						xtype: 'tbseparator'
					}, {
						icon: '<?=MEDIA?>icon/application_form_publish_remove.png',
						text: '<?=$this->db->escape_str($this->lang->line("CANCELLING_OF_PUBLISHED_DATA"))?>',
						ref: '../unpublishBtn',
						disabled: true,
						handler: function(){
							DataEdit.unpublish('ART', Ext.getCmp('artGrid').getSelectionModel().getSelections()[0].data.artId, Ext.getCmp('artGrid').getSelectionModel().getSelections()[0].data.artName, 2);
						}
					}
				]
			},

			bbar: 
				new Ext.PagingToolbar({
					pageSize: <?=$this->config->item("adminGridPageSize")?>,
					store: store,
					displayInfo: true,
					plugins: new Ext.ux.ProgressBarPager()
				}),

			plugins:[
				new Ext.ux.grid.Search({
					minChars:2,
					iconCls: 'icon-zoom',
					searchText:'<?=$this->db->escape_str($this->lang->line("SEARCH"))?>',
					position:'top',
					minCharsTipText:'<?=$this->db->escape_str($this->lang->line("MINIMUM_TWO_CHARACTERS_IS_REQUIRED"))?>',
					selectAllText: '<?=$this->db->escape_str($this->lang->line("SELECT_ALL"))?>',
					width:200,
					disableIndexes:['entList'],
					autoFocus:true
				})]

		});

		grid.render('grid-table-article');

		grid.getSelectionModel().on('selectionchange', function(sm){
			Ext.getCmp('artGrid').removeBtn.setDisabled(sm.getCount() < 1);
			Ext.getCmp('artGrid').editBtn.setDisabled(sm.getCount() < 1);
			Ext.getCmp('artGrid').publishBtn.setDisabled(!(sm.getCount() && sm.getSelected().data.artTempFlag == 'I'));
			Ext.getCmp('artGrid').publishBtnDelete.setDisabled(!(sm.getCount() && sm.getSelected().data.artTempFlag == 'I'));
			Ext.getCmp('artGrid').unpublishBtn.setDisabled(sm.getCount() < 1);
			Ext.getCmp('artGrid').previewBtn.setDisabled(sm.getCount() < 1);
		});

		store.load({params:{start:0, limit:<?=$this->config->item("adminGridPageSize")?>}});

		function save() {
			$('#art_lead').val(CKEDITOR.instances.art_lead.getData());
			$('#art_text').val(CKEDITOR.instances.art_text.getData());
			if(!articleForm.getForm().isValid()) {
				Ext.Msg.show({
					title:'<?=$this->db->escape_str($this->lang->line("ERROR"))?>',
					msg: '<?=$this->db->escape_str($this->lang->line("PLEASE_CORRECT_THE_ERRORS"))?>',
					buttons: Ext.Msg.OK,
					icon: Ext.MessageBox.WARNING
				});
			} else {
				if(articleForm.getForm().isDirty() || true /* ckeditor miatt */) {
					articleForm.getForm().submit({
						url: '<?=site_url()?>admin/article_insert_update',
						success: function(form, resp){
							if(resp.result.error) {
								Ext.Msg.show({
									title:'<?=$this->db->escape_str($this->lang->line("ERROR"))?>',
									msg: resp.result.error,
									buttons: Ext.Msg.OK,
									icon: Ext.MessageBox.ERROR
								});
							} else {
								winArticle.close();
								store.reload(store.lastOptions);
							}
						}
					});
				} else {
					winArticle.close();
					store.reload(store.lastOptions);
				}
			}
		};

		function close() {
			winArticle.close();
		};

		function removeArticle(btn) {
			if(btn == 'yes') {
				Ext.Ajax.request({url: '<?=site_url()?>admin/article_insert_update', params: 'del=1&artId=' + grid.getSelectionModel().getSelections()[0].data.artId, success: function() {
					store.reload(store.lastOptions);
					}
				});
			}
		}

	})
</script>


<div id="grid-table-article"></div>